package com.nbsaas.boot.nbtask.controller;

import com.nbsaas.boot.nbtask.domain.OrderMessage;
import com.nbsaas.boot.nbtask.task.OrderProducer;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/orders")
public class OrderController {

    private final OrderProducer orderProducer;

    public OrderController(OrderProducer orderProducer) {
        this.orderProducer = orderProducer;
    }

    @PostMapping
    public String createOrder(@RequestBody OrderMessage orderMessage) {
        orderProducer.sendOrder(orderMessage);
        return "Order submitted: " + orderMessage.getOrderId();
    }

    @RequestMapping(value = "/createOrder1")
    public String createOrder1(OrderMessage orderMessage) {
        orderProducer.sendOrder(orderMessage);
        return "Order submitted: " + orderMessage.getOrderId();
    }

    @RequestMapping(value = "/createOrder2")
    public String createOrder2(OrderMessage orderMessage) {
        orderProducer.sendOrder(orderMessage, 5_1000);
        return "Order submitted: " + orderMessage.getOrderId();
    }
}
